

var rt = window.external.mxGetRuntime();
rt.post("getzoom");
rt.onAppEvent = function(obj) {
    if(obj.type == "ACTION_SHOW") {
        rt.post("getzoom");
    }
}



function changeZoom() {
    var zoom = document.querySelectorAll("#size")[0].value;
    document.querySelectorAll("#pageSizeSpan")[0].innerHTML = (zoom * 100).toString().substring(0, 3) + "%";
    rt.post("zoom", zoom);
    document.querySelectorAll("#ok")[0].disabled = false;
}

function resetZoom() {
    document.querySelectorAll("#size")[0].value = 1;
    document.querySelectorAll("#pageSizeSpan")[0].innerHTML = "100%";
    rt.post("zoom", 1);
    document.querySelectorAll("#ok")[0].disabled = false;
}

rt.listen("changePanelZoom", function(object) {
    // 当zoom无值时，panel显示为1
    if(object.zoom =="") {
        object.zoom = 1;
    }
    if(document.querySelectorAll("#size")[0].value != object.zoom) {
        document.querySelectorAll("#ok")[0].disabled = false;
        document.querySelectorAll("#size")[0].value = object.zoom;
    }
    
    //TODO del 下面一行
    var zoom = document.querySelectorAll("#size")[0].value;
    document.querySelectorAll("#pageSizeSpan")[0].innerHTML = (zoom * 100).toString().substring(0, 3) + "%";

    //alert(object.savezoom);
    if(object.savezoom == "") {
        document.querySelectorAll("#cencelB")[0].disabled = true;
    }else {
        document.querySelectorAll("#cencelB")[0].disabled = false;
    }

        //alert(rt.storage.getConfig("isauto"))
        if(rt.storage.getConfig("isauto") == "true") {
            document.querySelectorAll("#isauto")[0].checked = true;
        }else {
            document.querySelectorAll("#isauto")[0].checked = false;
        }
});

function save() {
    var zoom = document.querySelectorAll("#size")[0].value;
    rt.post("savezoom", zoom);
    document.querySelectorAll("#ok")[0].disabled = true;
    document.querySelectorAll("#cencelB")[0].disabled = false;
}

function isauto() {
    rt.post("changeAuto", document.querySelectorAll("#isauto")[0].checked);
}

function clearR() {
    rt.post("clear");
    document.querySelectorAll("#cencelB")[0].disabled = true;
    document.querySelectorAll("#ok")[0].disabled = false;
}